//
//  XGTopicCellBottomView.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/30.
//  Copyright © 2018 itcast. All rights reserved.
//

#import <Masonry/Masonry.h>

#import "XGTopicCellBottomView.h"

#import "XGTopicModel.h"

@interface XGTopicCellBottomView ()

/// 顶按钮
@property (nonatomic,strong) UIButton *likeButton;
/// 踩按钮
@property (nonatomic,strong) UIButton *unlikeButton;
/// 转发按钮
@property (nonatomic,strong) UIButton *retweetButton;
/// 回复按钮
@property (nonatomic,strong) UIButton *commentButton;

@end

@implementation XGTopicCellBottomView

#pragma mark - 解析模型

- (void)setTopicModel:(XGTopicModel *)topicModel
{
    _topicModel = topicModel;
    
    [self.likeButton setTitle:[NSString stringWithFormat:@"%zd",topicModel.ding] forState:UIControlStateNormal];
     [self.unlikeButton setTitle:[NSString stringWithFormat:@"%zd",topicModel.cai] forState:UIControlStateNormal];
     [self.retweetButton setTitle:[NSString stringWithFormat:@"%zd",topicModel.repost] forState:UIControlStateNormal];
     [self.commentButton setTitle:[NSString stringWithFormat:@"%zd",topicModel.comment] forState:UIControlStateNormal];
}

#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
    UIView *lineView2 = [[UIView alloc] init];
    lineView2.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
    UIView *lineView3 = [[UIView alloc] init];
    lineView3.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
    
    [self addSubview:self.likeButton];
    [self addSubview:self.unlikeButton];
    [self addSubview:self.retweetButton];
    [self addSubview:self.commentButton];
    [self addSubview:lineView1];
    [self addSubview:lineView2];
    [self addSubview:lineView3];
    
    [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self);
    }];
    
    [self.unlikeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.likeButton.mas_right).offset(1);
        make.centerY.equalTo(self.likeButton);
        make.size.equalTo(self.likeButton);
    }];
    
    [self.retweetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.unlikeButton.mas_right).offset(1);
        make.centerY.equalTo(self.likeButton);
        make.size.equalTo(self.likeButton);
    }];
    
    [self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.retweetButton.mas_right).offset(1);;
        make.centerY.equalTo(self.likeButton);
        make.size.equalTo(self.likeButton);
        make.right.equalTo(self);
    }];
    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeButton);
        make.left.equalTo(self.likeButton.mas_right);
        make.width.mas_equalTo(1);
        make.height.equalTo(self).multipliedBy(0.6);
    }];
    
    
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeButton);
        make.left.equalTo(self.unlikeButton.mas_right);
        make.size.equalTo(lineView1);
    }];
    
    [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeButton);
        make.left.equalTo(self.retweetButton.mas_right);
        make.size.equalTo(lineView1);
    }];
}

#pragma mark - 懒加载

- (UIButton *)likeButton
{
    if (_likeButton == nil) {
        _likeButton = [UIButton buttonWithTitle:@"999" fontSize:15 titleColor:[UIColor lightGrayColor] imageName:@"mainCellDing" highlightedImageName:@"mainCellDingClick" target:nil action:nil];
    }
    
    return _likeButton;
}

- (UIButton *)unlikeButton
{
    if (_unlikeButton == nil) {
        _unlikeButton = [UIButton buttonWithTitle:@"999" fontSize:15 titleColor:[UIColor lightGrayColor] imageName:@"mainCellCai" highlightedImageName:@"mainCellCaiClick" target:nil action:nil];
    }
    
    return _unlikeButton;
}

- (UIButton *)retweetButton
{
    if (_retweetButton == nil) {
        _retweetButton = [UIButton buttonWithTitle:@"999" fontSize:15 titleColor:[UIColor lightGrayColor] imageName:@"mainCellShare" highlightedImageName:@"mainCellShareClick" target:nil action:nil];
    }
    
    return _retweetButton;
}

- (UIButton *)commentButton
{
    if (_commentButton == nil) {
        _commentButton = [UIButton buttonWithTitle:@"999" fontSize:15 titleColor:[UIColor lightGrayColor] imageName:@"mainCellComment" highlightedImageName:@"mainCellCommentClick" target:nil action:nil];
    }
    
    return _commentButton;
}


@end
